#pragma once

#include <vector>
#include <string>

#include <fcntl.h>

class Util
{
public:
    static bool setNonBlock(int fd)
    {
        int f1 = fcntl(fd,F_GETFL);
        if(f1 < 0) return false;
        fcntl(fd,F_SETFL,f1 | O_NONBLOCK);
        return true;
    }

    static bool StringSplit(const std::string &str, const std::string &SEP, std::vector<std::string> *res)
    {
        int start = 0;
        while (start < str.size())
        {
            // 1@@+@@2
            int pos = str.find(SEP, start);
            if (pos == std::string::npos)
                break;
            res->push_back(str.substr(start, pos - start));

            start = pos + SEP.size();
        }

        if (start < str.size())
        {
            res->push_back(str.substr(start));
        }

        return true;
    }


    static int toInt(const std::string& str)
    {
        return atoi(str.c_str());
    }

    static bool isop(char c)
    {
        std::string ops = "+-*/%";
        for(auto e:ops)
        {
            if(c == e) return true;
        }

        return false;
    }
};